sizerequest: Assert that min_size >= 0
authorTimm Bäder <mail@baedert.org>
Sun, 4 Jun 2017 18:13:26 +0000 (20:13 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 20 Jul 2017 01:27:13 +0000 (21:27 -0400)
This should generally be true, so remove the checks from gtkbox.c and
move it into gtksizerequest.c

gtk/gtkbox.c
gtk/gtksizerequest.c

index 312f5357823e4dd5f28e17676aa8353954110abd..d71aa48b80aee9fb43f8781cc70b390163d31eb2 100644 (file)
@@ -433,24 +433,6 @@ gtk_box_size_allocate_no_center (GtkWidget           *widget,
                           &sizes[i].minimum_size, &sizes[i].natural_size,
                           NULL, NULL);
 
-      /* Assert the api is working properly */
-      if (sizes[i].minimum_size < 0)
-       g_error ("GtkBox child %s minimum %s: %d < 0 for %s %d",
-                gtk_widget_get_name (GTK_WIDGET (child->widget)),
-                (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
-                sizes[i].minimum_size,
-                (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "height" : "width",
-                (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? allocation->height : allocation->width);
-
-      if (sizes[i].natural_size < sizes[i].minimum_size)
-       g_error ("GtkBox child %s natural %s: %d < minimum %d for %s %d",
-                gtk_widget_get_name (GTK_WIDGET (child->widget)),
-                (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
-                sizes[i].natural_size,
-                sizes[i].minimum_size,
-                (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "height" : "width",
-                (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? allocation->height : allocation->width);
-
       children_minimum_size += sizes[i].minimum_size;
 
       sizes[i].data = child;
@@ -1117,20 +1099,6 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
                               &sizes[i].minimum_size, &sizes[i].natural_size,
                               NULL, NULL);
 
-         /* Assert the api is working properly */
-         if (sizes[i].minimum_size < 0)
-           g_error ("GtkBox child %s minimum %s: %d < 0",
-                    gtk_widget_get_name (GTK_WIDGET (child->widget)),
-                    (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
-                    sizes[i].minimum_size);
-
-         if (sizes[i].natural_size < sizes[i].minimum_size)
-           g_error ("GtkBox child %s natural %s: %d < minimum %d",
-                    gtk_widget_get_name (GTK_WIDGET (child->widget)),
-                    (private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
-                    sizes[i].natural_size,
-                    sizes[i].minimum_size);
-
           children_minimum_size += sizes[i].minimum_size;
 
          sizes[i].data = child;
index 7505c8a4dbf26e1127a169daac995768aa6cba3e..ea1b7c0663bdfa242a0aef1a65f5cd9ad36803d1 100644 (file)
@@ -238,6 +238,17 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
                          G_OBJECT_TYPE_NAME (widget), widget, min_size, nat_size, for_size);
 
             }
+
+          nat_size = min_size;
+        }
+      else if (G_UNLIKELY (min_size < 0))
+        {
+          g_warning ("%s %p reported min %s %d, but sizes must be >= 0",
+                     G_OBJECT_TYPE_NAME (widget), widget,
+                     orientation == GTK_ORIENTATION_HORIZONTAL ? "width" : "height",
+                     min_size);
+          min_size = 0;
+          nat_size = MAX (0, min_size);
         }
 
       adjusted_min     = min_size;